// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TradingClientApp.java

package com.boci.clientapp.main;

import com.boci.clientapp.authentication.action.LogoutAction;
import com.boci.common.util.*;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.*;
import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Logger;
import javax.swing.JFrame;

// Referenced classes of package com.boci.clientapp.main:
//            RestoreFrame, ApplicationService, ClientAppLoader

public class TradingClientApp extends JFrame
    implements WindowListener, WindowStateListener
{

    public static void main(String args[])
    {
        ClientAppLoader.startup(true, null);
    }

    private void initConfig(Locale pLocale)
    {
        String strWindowState = "NORMAL";
        strWinTitle = ClientAppLoader.getMessagesConfigurator().getUIMessages("WINDOW.TITLE", pLocale);
        setMaximizedBounds(new Rectangle(750, 450));
        ClientAppLoader.getAppConfigurator();
        Properties appUIConfigProp = AppConfigurator.getAppUIConfigProperties();
        try
        {
            intAppX = Integer.parseInt(appUIConfigProp.getProperty("APP_X"));
            intAppY = Integer.parseInt(appUIConfigProp.getProperty("APP_Y"));
            intAppWidth = Integer.parseInt(appUIConfigProp.getProperty("APP_WIDTH"));
            intAppHeight = Integer.parseInt(appUIConfigProp.getProperty("APP_HEIGHT"));
        }
        catch(NumberFormatException e)
        {
            intAppX = 0;
            intAppY = 0;
            intAppWidth = 750;
            intAppHeight = 310;
            strWindowState = "NORMAL";
            logger.info(StringUtil.formatException(e));
        }
        strWindowState = appUIConfigProp.getProperty("APP_STATE");
        restoreFrame = new RestoreFrame(this, strWinTitle);
        addWindowStateListener(this);
        if(strWindowState.equals("MINIMIZED"))
        {
            intAppX = 0;
            intAppY = 0;
            intAppWidth = 750;
            intAppHeight = 310;
        } else
        if(strWindowState.equals("MAXIMIZED"))
        {
            initMaxFlag = true;
            setExtendedState(6);
        }
        setLocation(intAppX, intAppY);
        setSize(intAppWidth, intAppHeight);
    }

    public void setTitle(String pTitle)
    {
        super.setTitle(pTitle);
        restoreFrame.setTitle(pTitle);
    }

    public TradingClientApp(Locale pLocale)
    {
        logger = CMLogger.getInstance();
        initMaxFlag = false;
        initMinFlag = false;
        intAppX = 0;
        intAppY = 0;
        intAppWidth = 750;
        intAppHeight = 310;
        initConfig(pLocale);
        setIconImage(ClientAppLoader.getIconImage());
        setTitle(strWinTitle);
        setDefaultCloseOperation(0);
        addWindowListener(this);
    }

    public void showMainFrame(boolean pMainFrame)
    {
        if(initMinFlag)
        {
            restoreFrame.setVisible(pMainFrame, ApplicationService.getInstance().getCurrentLocale());
            setVisible(!pMainFrame);
        } else
        {
            restoreFrame.setVisible(!pMainFrame, ApplicationService.getInstance().getCurrentLocale());
            setVisible(pMainFrame);
        }
        if(restoreFrame.isVisible())
        {
            restoreFrame.setState(0);
            ClientAppLoader.setOnTop("com.boci.clientapp.main.RestoreFrame", true);
        } else
        if(isVisible())
            ClientAppLoader.setOnTop("com.boci.clientapp.main.TradingClientApp", false);
    }

    public void windowOpened(WindowEvent windowevent)
    {
    }

    public void windowClosing(WindowEvent e)
    {
        ApplicationService appServ = ApplicationService.getInstance();
        if(appServ.showYesNoDialog(null, "MAIN.CONFIRM_EXIT"))
        {
            try
            {
                if(e.getSource().equals(restoreFrame))
                {
                    saveMinProperties("MINIMIZED", Integer.toString(restoreFrame.getX()), Integer.toString(restoreFrame.getY()));
                } else
                {
                    String strWindowState = "NORMAL";
                    if(getExtendedState() == 6)
                        strWindowState = "MAXIMIZED";
                    saveProperties(strWindowState);
                }
                String strActionType = "EXIT";
                LogoutAction action = new LogoutAction();
                action.doProcess(null, strActionType);
            }
            catch(Exception e1)
            {
                logger.info(StringUtil.formatException(e1));
            }
            System.exit(0);
        }
        appServ.setFocus();
    }

    public void windowClosed(WindowEvent windowevent)
    {
    }

    public void windowIconified(WindowEvent e)
    {
        showMainFrame(false);
    }

    public void windowDeiconified(WindowEvent windowevent)
    {
    }

    public void windowActivated(WindowEvent windowevent)
    {
    }

    public void windowDeactivated(WindowEvent windowevent)
    {
    }

    public void saveProperties(String pWindowState)
        throws IOException
    {
        AppConfigurator ac = ClientAppLoader.getAppConfigurator();
        AppConfigurator _tmp = ac;
        Properties props = AppConfigurator.getAppUIConfigProperties();
        Point location = getLocation();
        String strX = Integer.toString((int)location.getX());
        String strY = Integer.toString((int)location.getY());
        String strWidth = Integer.toString(getWidth());
        String strHeight = Integer.toString(getHeight());
        props.setProperty("APP_X", strX);
        props.setProperty("APP_Y", strY);
        props.setProperty("APP_WIDTH", strWidth);
        props.setProperty("APP_HEIGHT", strHeight);
        props.setProperty("APP_STATE", pWindowState);
        PropertiesUtil.storeProperties(props, ac.getStrAppUIConfigPath());
    }

    public void saveMinProperties(String pWindowState, String pX, String pY)
        throws IOException
    {
        AppConfigurator ac = ClientAppLoader.getAppConfigurator();
        AppConfigurator _tmp = ac;
        Properties props = AppConfigurator.getAppUIConfigProperties();
        String width = Integer.toString(getWidth());
        String height = Integer.toString(getHeight());
        props.setProperty("APP_X", pX);
        props.setProperty("APP_Y", pY);
        props.setProperty("APP_WIDTH", width);
        props.setProperty("APP_HEIGHT", height);
        props.setProperty("APP_STATE", pWindowState);
        PropertiesUtil.storeProperties(props, ac.getStrAppUIConfigPath());
    }

    public void windowStateChanged(WindowEvent e)
    {
        if(initMaxFlag && e.getNewState() == 0)
        {
            setSize(750, 310);
            setLocation(0, 0);
            initMaxFlag = false;
        }
    }

    public void restore()
    {
        if(initMinFlag)
        {
            setExtendedState(0);
            setSize(750, 310);
            setLocation(0, 0);
            initMinFlag = false;
        }
        int currState = getExtendedState();
        if(currState == 7)
            setExtendedState(6);
        else
            setExtendedState(0);
        showMainFrame(true);
    }

    private String strWinTitle;
    private Logger logger;
    private RestoreFrame restoreFrame;
    private boolean initMaxFlag;
    private boolean initMinFlag;
    private int intAppX;
    private int intAppY;
    private int intAppWidth;
    private int intAppHeight;
}
